<#include '/admin/header.html' >
<style>
td .layui-btn-small{
background:#1E9FFF;
}
</style>
<div  class="admin-main">
	   <div>
        <!--提示区域  -->
        <div class="page_explain">
            <h2>操作提示</h2>
	            <ul>
	                <li><span>·</span>此广告位显示的是具体广告位下面的所有广告列表。</li>
	                <li><span>·</span>添加或者修改广告的时候，可以直接选择相应广告位置和是否开启选择项。</li>
	            </ul>
        </div>
        <!--按钮操作  -->
        <div class="table_control">
            <div class="table_opera">
                <button type="button" class="layui-btn layui-btn-primary layui-btn-small" title="说明" id="explain"><i class="layui-icon">&#xe607;</i></button>
            </div>
        </div>
    </div>
		<form id="dly_centerform">
		 <table id="advdata" class="layui-table site-table table-hover" width="100%" lay-skin="line" >
				<thead>
					<tr>
						<th>ID</th>
						<th>广告名称</th>
						<th>所属广告位</th>
						<th>状态</th>
						<th>操作</th>
					</tr>
				</thead>
			</table>
			<div id="addBrand" ></div>
		</form>
		<div id="divdia"></div>
	</div>
<script type="text/javascript">
var table
$(function(){
	 table= $('#advdata').DataTable({
		"language": {
	        "url": "${staticserver}/media/zh_CN.txt"
	    },
	    "processing": true,
	    "serverSide": true,
	    "ordering": false,
	    "searching": false,
	    "lengthChange": false,
	    ajax: {
	        //指定数据源
	        type:"post",
	        url: '${ctx}/core/admin/adv/list-json.do?acid=${acid!''}',
	    },
	    columns: [ //定义列
            {"data": function (obj) {
                return '<input type="checkbox" name="aid" class="fly-checkbox" value=' + obj.aid + '>';
            		}},
	        {data: "aname"},
	        {data: "cname"},
	        {data: null,"render": function(data, type, row) {
	        	var val;
	    		if (data.isclose == 0) {    
	    			val = "已开启&nbsp;<a class='layui-btn layui-btn-small' href='javascript:void(0);' name ='aid' aid='"+data.aid+"' onclick='doStop("+data.aid+")' />关闭</a>";
	    		} else if (data.isclose == 1) {
	    			val = "已停用&nbsp;<a class='layui-btn layui-btn-small' href='javascript:void(0);' name ='aid' aid='"+data.aid+"' onclick='doStart("+data.aid+")' />开启</a>";
	    		}
	    		return val;
	       	}},
	        {data: null,"render": function(data, type, row) {
	        	return "<a class='layui-btn layui-btn-small _aa' name='aid'  onclick='editadv("+ data.aid + ")'>修改</a>"; 		//获取值:data["brand_id"]
	       	}}
	     ]
	});
});

//修改弹框
function editadv(aid){
	layer.open({
        title:"修改广告",//标题
        maxmin :true,//右上角可否放大缩小
        type:2,//弹框的类型
        shade: [0.3, '#000'],//黑色背景
        shadeClose:false,//黑色背景是否可以点击关闭
        content:"edit.do?advid=" + aid,
        area:['700px','500px'],//弹框大小
        scrollbar: false,//是否允许浏览器出现滚动条
    });
}
   //关闭
function doStop(advid){
	var that =this;
	var options = {
		url : ctx + "/core/admin/adv/stop.do?advid="+advid,
		type : "POST",
		dataType : 'json',
		success : function(result) {	
			if(result.result==1){
				$.Loading.success(result.message);
				table.ajax.url(ctx+"/core/admin/adv/list-json.do?acid=${acid!''}").load();
			}else{
				$.Loading.error(result.message);
			}
		},
		error : function(e) {
			$.Loading.error("出现错误 ，请重试");
		}
	};
	$.ajax(options);
}
//启动
function doStart(advid){
	var that =this;
	var options = {
		url : ctx + "/core/admin/adv/start.do?advid="+advid,
		type : "POST",
		dataType : 'json',
		success : function(result) {	
			if(result.result==1){
				$.Loading.success(result.message);
				table.ajax.url(ctx+"/core/admin/adv/list-json.do?acid=${acid!''}").load();
			}else{
				$.Loading.error(result.message);
			}
			$("#advdata").datagrid('reload');
		},
		error : function(e) {
			$.Loading.error("出现错误 ，请重试");
		}
	};
	$.ajax(options);
}
	

</script>
<#include '/admin/footer.html' >
